<template>
	<view>
		<qiun-data-charts type="column" :chartData="column"></qiun-data-charts>
		<qiun-data-charts type="line" :chartData="column2"></qiun-data-charts>
		<qiun-data-charts type="pie" :chartData="pie"></qiun-data-charts>
	</view>
</template>

<script>
	import qiunChartData from 'components/qiun-data-charts/qiun-data-charts.vue'
	export default {
		components: {
			qiunChartData,
		},
		data() {
			return {
				base:'',
				column: {
					categories: ['1'],
					series: [{
						name: '男',
						data: ['1']
					},
					{
						name: '女',
						data: ['1']
					}]
				},
				column2: {
					categories: ['甘A','甘B','甘C'],
					series: [{
						name: '车牌',
						data: [10,20,30]
					}]
				},
				pie: {
					series: [{
						name: '车牌',
						data: 10
					}]
				}
			}
		},
		onLoad() {
			this.base = uni.getStorageSync('serIP')
			this.getxi()
			this.getzhiwei()
		},
		methods: {
			getxi() {
				this.$get(this.base + '/prod-api/press/press/list').then((res) => {
					let xin = res.rows.slice(0,1)
					this.column.categories = []
					xin.forEach((item)=>{
						this.column.categories.push(this.filstr(item.title))
					})
					this.$get(this.base+'/prod-api/press/comments/list').then((res)=>{
						let pinlun =res.rows
						var i = 0
						const _this = this
						function gesu(){
							if(i>=res.rows.length){
								return
							}
							_this.$get(_this.base+'/prod-api/system/user/list',{
								userName:res.rows[i].userName
							}).then((res)=>{
								console.log(res.rows)
								i++
								gesu()
							})
						}
					})
				})
			},
			getzhiwei(){
				this.$get(this.base+'/prod-api/api/job/post/list').then((res)=>{
					let zhiwei = []
					res.rows.forEach((item)=>{
						if(item.professionName != ''|item.professionName != null){
							zhiwei.push(item)
						}
					})
					let shu = this.arr(zhiwei)
					this.pie.series = []
					shu.forEach((item)=>{
						this.pie.series.push({
							name:item.professionName,
							data:item.children.length
						})
					})
				})
			},
			arr(arr){
				let list = [],map = {}
				for (var i = 0; i < arr.length; i++) {
					var item = arr[i]
					if(!map[item.professionName]){
						list.push({
							professionName:item.professionName,
							children:[item]
						})
						map[item.professionName] = item
					}else{
						for (var j = 0; j < list.length; j++) {
							var nitem = list[j]
							if(nitem.professionName == item.professionName){
								nitem.children.push(item)
							}
						}
					}
				}
				return list
			},
			filstr(str){
				return str.length>4?str.substring(0,3)+'...':str
			}
		}
	}
</script>

<style>

</style>
